﻿
using MediatR;
using System.WXT.Infrstructre.Interface;
using System.WXT.WebAPI.Application.Command.CraftCommand;

namespace System.WXT.WebAPI.Application.CommandHandlers.CraftCommandHandlers
{
    public class CraftAddCommandHandlers:IRequestHandler<CraftAddCommand,int>
    {
        protected readonly ICraftRepository craftRepository;

        public CraftAddCommandHandlers(ICraftRepository craftRepository)
        {
            this.craftRepository = craftRepository;
        }
        /// <summary>
        /// 生产工艺添加
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<int> Handle(CraftAddCommand request, CancellationToken cancellationToken)
        {
            // long timestamp = request.craftManageDate.ToString("yyyy-HH-dd");  // 时间戳类型为 long
            //DateTime dateTime = DateTimeOffset.FromUnixTimeSeconds(timestamp).DateTime;
            //var s = request.craftManageDate.Value.ToUniversalTime();
            var res = request.craftManageDate.Value.ToUniversalTime();


            var list = await craftRepository.Add(new Domain.Craft { craftManagenumbering = request.craftManagenumbering, craftManageName = request.craftManageName, craftManageState = request.craftManageState, craftManageFinishName = request.craftManageFinishName, craftManageDate = res, craftManageAddName = request.craftManageAddName,AddName="李明",AddTime=DateTime.Now.ToUniversalTime() });
            
            return list;
        }
    }
}
